// 智能指针类

template<typename T>
class sharedPtr
{
private:
    /* data */
    size_t* m_count_;
    T* m_ptr_;

public:
    // 构造函数
    sharedPtr(/* args */):m_ptr_(nullptr),m_count_(new size_t){};
    sharedPtr(T* ptr):m_ptr_(ptr),m_count_(new size_t){
        m_count_ = 1;
    }
    // 析构函数
    ~sharedPtr(){
        --(*m_count_);
        if(*m_count_==0){
            delete m_ptr_;
            delete m_count_;
            m_ptr_ = nullptr;
            m_count_=nullptr;
        }
    }

    // 拷贝构造
    sharedPtr(const sharedPtr& ptr){
        m_count_ = ptr.m_count_;
        m_ptr_ = ptr.m_ptr_;
        ++(*m_count_);
    }

    // 拷贝赋值
    void operator=(const sharedPtr& ptr){
        sharedPtr(std::move(ptr));
    }

    // 移动构造
    sharedPtr(sharedPtr&& ptr):m_ptr_(ptr.m_ptr_),m_count_(ptr.m_count_){
        ++(*m_count_);
    }

    // 移动赋值
    void operator=(sharedPtr&& ptr){
        sharedPtr(std::move(ptr));
    }

    // 解引用
    T& operator*(){
        return *m_ptr_;
    }

    // 箭头
    T* operator->(){
        return m_ptr_;
    }

    // bool
    operator bool(){
        return m_ptr_==nullptr;
    }

    T* get(){
        return m_ptr_;
    }

    size_t use_count(){
        return *m_count_;
    }

    bool unique(){
        return *m_count_==1;
    }

    void swap(sharedPtr& prt){
        std::swap(*this,ptr);
    }
};

